﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace EnglishAuction.BUS
{
    public class ChiSoLikeBUS
    {
        public static int Count(int sanPhamId)
        {
            using (var context = new EnglishAuctionEntities())
            {
                return context.ChiSoLikes.Where(s => s.SanPhamId == sanPhamId).Count();
            }
        }

        public static bool Insert(ChiSoLike chisoLike)
        {
            bool result = true;
            using (var context = new EnglishAuctionEntities())
            {
                context.ChiSoLikes.Add(chisoLike);
                context.SaveChanges();
            }

            return result;
        }

        public static bool Delete(int sanPhamId, int nguoiDungId)
        {
            bool result = true;
            using (var context = new EnglishAuctionEntities())
            {
                ChiSoLike chisolike = context.ChiSoLikes.Where(p => p.NguoiDungId == nguoiDungId && p.SanPhamId == sanPhamId).FirstOrDefault();
                if (chisolike != null)
                {
                    context.ChiSoLikes.Remove(chisolike);
                    context.SaveChanges();
                }
            }

            return result;
        }

        public static bool Check(int sanPhamId, int nguoiDungId)
        {
            using (var context = new EnglishAuctionEntities())
            {
                ChiSoLike chisolike = context.ChiSoLikes.Where(p => p.NguoiDungId == nguoiDungId && p.SanPhamId == sanPhamId).FirstOrDefault();
                if (chisolike == null)
                    return false;
                return true;
            }
        }
    }
}